﻿using Cocbook_DTO;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Sale_and_manage
{
    public partial class Mainform : DevComponents.DotNetBar.Metro.MetroAppForm
    {
        private int childFormNumber = 0;

        public Mainform()
        {
            InitializeComponent();

        }

        public static Staff staff;
        public bool logOut = false;

        private void ShowNewForm(object sender, EventArgs e)
        {
            DevComponents.DotNetBar.Metro.MetroForm childForm = new  DevComponents.DotNetBar.Metro.MetroForm();
            childForm.MdiParent = this;
            childForm.Text = "Window " + childFormNumber++;
            childForm.Show();
        }

        private void OpenFile(object sender, EventArgs e)
        {
            OpenFileDialog openFileDialog = new OpenFileDialog();
            openFileDialog.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.Personal);
            openFileDialog.Filter = "Text Files (*.txt)|*.txt|All Files (*.*)|*.*";
            if (openFileDialog.ShowDialog(this) == DialogResult.OK)
            {
                string FileName = openFileDialog.FileName;
            }
        }

        private void SaveAsToolStripMenuItem_Click(object sender, EventArgs e)
        {
            SaveFileDialog saveFileDialog = new SaveFileDialog();
            saveFileDialog.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.Personal);
            saveFileDialog.Filter = "Text Files (*.txt)|*.txt|All Files (*.*)|*.*";
            if (saveFileDialog.ShowDialog(this) == DialogResult.OK)
            {
                string FileName = saveFileDialog.FileName;
            }
        }

        private void ExitToolsStripMenuItem_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void CutToolStripMenuItem_Click(object sender, EventArgs e)
        {
        }

        private void CopyToolStripMenuItem_Click(object sender, EventArgs e)
        {
        }

        private void PasteToolStripMenuItem_Click(object sender, EventArgs e)
        {
        }



        private void CascadeToolStripMenuItem_Click(object sender, EventArgs e)
        {
            LayoutMdi(MdiLayout.Cascade);
        }

        private void TileVerticalToolStripMenuItem_Click(object sender, EventArgs e)
        {
            LayoutMdi(MdiLayout.TileVertical);
        }

        private void TileHorizontalToolStripMenuItem_Click(object sender, EventArgs e)
        {
            LayoutMdi(MdiLayout.TileHorizontal);
        }

        private void ArrangeIconsToolStripMenuItem_Click(object sender, EventArgs e)
        {
            LayoutMdi(MdiLayout.ArrangeIcons);
        }

        private void CloseAllToolStripMenuItem_Click(object sender, EventArgs e)
        {
            foreach (DevComponents.DotNetBar.Metro.MetroForm childForm in MdiChildren)
            {
                childForm.Close();
            }
        }


        private void Mainform_Load(object sender, EventArgs e)
        {
            tabUser.Text = staff.StaffName;
            if (staff.Position == "admin")
            {
                rbbAministrator.Enabled = true;
            }
            else
            {
                rbbAministrator.Enabled = false;
            }
        }

        private void btnSearch_Click(object sender, EventArgs e)
        {
            frmBookSearch frm = new frmBookSearch();
            frm.MdiParent = this;
            frm.Show();
        }

        private void btnFilter_Click(object sender, EventArgs e)
        {
            frmBookFilter frm = new frmBookFilter();
            frm.MdiParent = this;
            frm.Show();
        }

        private void btnShowBillList_Click(object sender, EventArgs e)
        {
            frmBillHistory frm = new frmBillHistory();
            frm.MdiParent = this;
            frm.Show();
        }

        private void btnAddNewCustomer_Click(object sender, EventArgs e)
        {
            frmAddCustomer frm = new frmAddCustomer();
            frm.MdiParent = this;
            frm.Show();
        }

        private void btnShowCustomerList_Click(object sender, EventArgs e)
        {
            frmManageCustomer frm = new frmManageCustomer();
            frm.MdiParent = this;
            frm.Show();
        }

        

        private void btnAddOrder_Click(object sender, EventArgs e)
        {
            int i = -1;
            bool check = true;
            
            FormCollection fr = Application.OpenForms;
            foreach (Form f in fr)
            {
                i = i + 1;
                if (f.Text == "Đặt sách")
                {
                    check = false;
                    break;
                }
            }
            if (check)
            {
                frmAddOrder frm = new frmAddOrder();
                frm.MdiParent = this;
                frm.Show();
            }
            else
            {
                fr[i].Activate();
            }
        }

        private void btnBookReport_Click(object sender, EventArgs e)
        {
            frmBookReport frm = new frmBookReport();
            frm.MdiParent = this;
            frm.Show();
        }

        

        private void btnExportCustomer_Click(object sender, EventArgs e)
        {
            frmCustomerReport frm = new frmCustomerReport();
            frm.MdiParent = this;
            frm.Show();
        }

        private void btnExportBook_Click(object sender, EventArgs e)
        {
            frmBookInfoExport frm = new frmBookInfoExport();
            frm.MdiParent = this;
            frm.Show();
        }

        private void btnAddProject_Click(object sender, EventArgs e)
        {
            frmAddNewProject frm = new frmAddNewProject();
            frm.MdiParent = this;
            frm.Show();
        }

        private void btnLogout_Click(object sender, EventArgs e)
        {
            logOut = true;
            this.Close();
        }


        private void Mainform_FormClosed(object sender, FormClosedEventArgs e)
        {
            if (logOut == false)
            {
                Application.Exit();
            }
        }

        private void btnAddBookInfo_Click(object sender, EventArgs e)
        {
            int i = -1;
            bool check = true;

            FormCollection fr = Application.OpenForms;
            foreach (Form f in fr)
            {
                i = i + 1;
                if (f.Text == "Nhập thông tin sách")
                {
                    check = false;
                    break;
                }
            }
            if (check)
            {
                frmImportBookInfo frm = new frmImportBookInfo();
                frm.MdiParent = this;
                frm.Show();
            }
            else
            {
                fr[i].Activate();
            }
        }

        private void btnAddUser_Click(object sender, EventArgs e)
        {
            frmAddStaff frm = new frmAddStaff();
            frm.MdiParent = this;
            frm.Show();
        }

        private void btnProjectManage_Click(object sender, EventArgs e)
        {
            frmProjectManage frm = new frmProjectManage();
            frm.MdiParent = this;
            frm.Show();
        }

        private void btnShowIndex_Click(object sender, EventArgs e)
        {
            frmShowIndex frm = new frmShowIndex();
            frm.MdiParent = this;
            frm.Show();
        }

        private void btnManageWareHouse_Click(object sender, EventArgs e)
        {
            frmManageWareHouse frm = new frmManageWareHouse();
            frm.MdiParent = this;
            frm.Show();
        }


        private void btnManageUser_Click(object sender, EventArgs e)
        {
            frmManageStaff frm = new frmManageStaff();
            frm.MdiParent = this;
            frm.Show();
        }


        private void buttonItem2_Click(object sender, EventArgs e)
        {
            frmMain frm = new frmMain();
            frm.MdiParent = this;
            frm.Show();
        }

        private void buttonItem1_Click(object sender, EventArgs e)
        {
            Process.Start("log.txt");
        }




    }
}
